package com.atguigu.dga.governance.mapper;

import com.atguigu.dga.governance.bean.GovernanceAssessTable;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 表治理考评情况 Mapper 接口
 * </p>
 *
 * @author wuzhida
 * @since 2024-07-02
 */
@Mapper
@DS("dga")
public interface GovernanceAssessTableMapper extends BaseMapper<GovernanceAssessTable> {

    @Select("SELECT\n" +
            "\tassess_date,\n" +
            "\ttable_name,\n" +
            "\tschema_name,\n" +
            "\ttec_owner,\n" +
            "\tAVG(IF(governance_type = 'SPEC', assess_score, NULL)) score_spec_avg,\n" +
            "\tAVG(IF(governance_type = 'STORAGE', assess_score, NULL)) score_storage_avg,\n" +
            "\tAVG(IF(governance_type = 'CALC', assess_score, NULL)) score_calc_avg,\n" +
            "\tAVG(IF(governance_type = 'QUALITY', assess_score, NULL)) score_quality_avg,\n" +
            "\tAVG(IF(governance_type = 'SECURITY', assess_score, NULL)) score_security_avg,\n" +
            "\tCOUNT(*) problem_num,\n" +
            "\tNOW() create_time\n" +
            "FROM governance_assess_detail\n" +
            "WHERE assess_date = #{assessDate}\n" +
            "GROUP BY \n" +
            "\tassess_date,\n" +
            "\ttable_name,\n" +
            "\tschema_name,\n" +
            "\ttec_owner")
    List<GovernanceAssessTable> getTableScore(String assessDate);
}
